//
//  RMMShopingTableViewCell.m
//  Romomo
//
//  Created by puman on 16/10/10.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "RMMShopingTableViewCell.h"

@implementation RMMShopingTableViewCell
{
    UIImageView *_imageV;
    UILabel *_titleLabel;
    UILabel *_priceLabel;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _cellSelectBut = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _cellSelectBut.frame = CGRectMake(0, 15, 60, 60);
      //  [_cellSelectBut setBackgroundImage:[UIImage imageNamed:@"可选@2x"] forState:(UIControlStateNormal)];
        [_cellSelectBut setImage:[UIImage imageNamed:@"可选@2x"] forState:(UIControlStateNormal)];
        [self.contentView addSubview:_cellSelectBut];
        
        _imageV = [[UIImageView alloc] initWithFrame:CGRectMake(_cellSelectBut.right, 15, 60, 60)];
        _imageV.layer.masksToBounds = YES;
        _imageV.layer.cornerRadius = 5;
        [self.contentView addSubview:_imageV];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_imageV.right + 12, _imageV.top, kScreenWideth - _imageV.right - 27, kMaric)];
        _titleLabel.font = kFont(14);
        _titleLabel.textColor = COLORFROMCODE(0x303137, 1);
        [self.contentView addSubview:_titleLabel];
        
        _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(_titleLabel.left , _imageV.bottom - kMaric, 80, kMaric)];
        _priceLabel.font = kBFont(16);
        _priceLabel.textColor = COLORFROMCODE(0x303137, 1);
        [self.contentView addSubview:_priceLabel];

        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(kScreenWideth - 83, _imageV.bottom - 24, 68, 24)];
        view.layer.masksToBounds = YES;
        view.layer.cornerRadius = 12;
        view.backgroundColor = COLORFROMCODE(0xEEEEEE, 1);
        [self.contentView addSubview:view];
        
        _countLabel = [[UILabel alloc] initWithFrame:view.bounds];
        _countLabel.font = kFont(13);
        _countLabel.textAlignment = NSTextAlignmentCenter;
        _countLabel.textColor = COLORFROMCODE(0x303137, 1);
        [view addSubview:_countLabel];
        
        _subBut = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _subBut.frame = CGRectMake(view.left - kRow, view.top - kRow, 44, 44);
        [_subBut setImage:[UIImage imageNamed:@"un-subtract@3x"] forState:(UIControlStateNormal)];
        [self.contentView addSubview:_subBut];

        _addBut = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _addBut.frame = CGRectMake(_subBut.right, _subBut.top, 44, 44);
        [_addBut setImage:[UIImage imageNamed:@"add@3x"] forState:(UIControlStateNormal)];
        [self.contentView addSubview:_addBut];
    }
    return self;
}
- (void)setModel:(RMMShopingModel *)model{
    NSString *bom_id = [RMMFileManager retrunObjWith:model.BOM_ID];
    if (bom_id.length > 0 && ![bom_id isEqualToString:@"(null)"]) {
        _titleLabel.text = model.SERVICE_NAME;
    } else {
        _titleLabel.text = model.SERVICE_NAME;
    }
    [_imageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kBaseImageUrl,model.IMAGEURL]] placeholderImage:[UIImage imageNamed:@"加载中@3x"]];
    _priceLabel.text = [NSString stringWithFormat:@"¥ %@",model.PRICE ];
    _countLabel.text = [RMMFileManager retrunObjWith:[NSString stringWithFormat:@"%@",model.COUNT]];
    if ([model.COUNT isEqualToNumber:@1]) {
        [_subBut setImage:[UIImage imageNamed:@"un-subtract@3x"] forState:(UIControlStateNormal)];
        _subBut.userInteractionEnabled = NO;
    } else {
        [_subBut setImage:[UIImage imageNamed:@"subtract@3x"] forState:(UIControlStateNormal)];
        _subBut.userInteractionEnabled = YES;
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
